import {Component} from "@angular/core";
import {HttpClient} from "@angular/common/http";
@Component({
  selector:"knowledges",
  template:`
    <button (click)="add()">添加知识点</button>
    <ul>
      <li *ngFor="let k of ks">
        {{k.knowledge}}
        <div class="toolBar">
        
          <a [routerLink]="['subjects',{knowledge:k.id,flag:1}]">每日三题</a>
          <a [routerLink]="['subjects',{knowledge:k.id,flag:0}]">知识点</a>
          <a [routerLink]="['editor',k.id]">添加详单</a>
        </div>
      </li>
    </ul>
  `
})
export class KnowledgesComponent{
  ks=[];
  constructor(private http:HttpClient){
    this.getKs();
  }
  getKs(){
    this.http.get<any[]>(`http://www.defangit.com:30002/api/knowledge`)
      .toPromise()
      .then(res=>{
        this.ks=res;
      });
  }
  add(){
    let rst=prompt("请输入知识点");
    this.http.post(`http://www.defangit.com:30002/api/knowledge`,{knowledge:rst})
      .toPromise()
      .then(res=>this.getKs());
  }
}
